/* 
自定义hook函数, 来记录点击的位置
*/
import {
  ref,
  onMounted,
  onBeforeUnmount,
} from "vue"

export default function () {
  const x = ref(-1)
    const y = ref(-1)

    function clickHandler(event: MouseEvent) {
      console.log('---------')
      x.value = event.pageX
      y.value = event.pageY
    }

    onMounted(() => {
      // 绑定点击监听
      document.addEventListener('click', clickHandler)
    })

    onBeforeUnmount(() => {
      document.removeEventListener('click', clickHandler)
    })

    return {
      x,
      y
    }
}